# Customise this file, documentation can be found here:
# https://github.com/fastlane/fastlane/tree/master/fastlane/docs
# All available actions: https://docs.fastlane.tools/actions
# can also be listed using the `fastlane actions` command

# Change the syntax highlighting to Ruby
# All lines starting with a # are ignored when running `fastlane`

# If you want to automatically update fastlane if a new version is available:
# update_fastlane

# This is the minimum version number required.
# Update this, if you use features of a newer version
fastlane_version "2.39.2"

default_platform :ios

platform :ios do
  before_all do
    # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
    cocoapods

  end

  # NOTE:配置version和build
  def prepare_version(options)
      # NOTE:
      today = Time.now
      todaytime = today.strftime("%Y%m%d%H%M%S")
      puts "current time" + todaytime
      increment_build_number(build_number:Time.now.strftime("%Y%m%d%H%M%S"))
      puts Time.now.strftime("%Y%m%d%H%M%S")
      increment_version_number(version_number:options[:version])
  end


  desc "Runs all the tests"
  lane :test do
    scan
  end

  desc "Submit a new Beta Build to Apple TestFlight"
  desc "This will also make sure the profile is up to date"
  lane :beta do |options|
    # match(type: "appstore") # more information: https://codesigning.guide
    prepare_version(options)
    gym(scheme: "YCVillageDoctor",
        export_method: "ad-hoc",
        output_name: "YCVillageDoctor" + Time.now.strftime("%Y%m%d%H%M%S")) # Build your app - more options available
    # pilot
    pgyer(api_key: "ff1484a58e8ad3e81abfef53ba9a0455", user_key: "8c5d924115c2d5b0fb436da69ab8ec28")


    # sh "your_script.sh"
    # You can also use other beta testing services here (run `fastlane actions`)
  end

  lane :appstore do |options|

    prepare_version(options)
    gym(scheme: "YCVillageDoctor",
        output_name: "YCVillageDoctor" + Time.now.strftime("%Y%m%d%H%M%S")) # Build your app - more options availabl
    appstore

  end

  desc "Deploy a new version to the App Store"
  lane :release do
    # match(type: "appstore")
    # snapshot
    gym(scheme: "YCVillageDoctor") # Build your app - more options available
    deliver(force: true)
    # frameit
  end

  # You can define as many lanes as you want

  after_all do |lane|
    # This block is called, only if the executed lane was successful

    # slack(
    #   message: "Successfully deployed new App Update."
    # )
  end

  error do |lane, exception|
    # slack(
    #   message: exception.message,
    #   success: false
    # )
  end
end


# More information about multiple platforms in fastlane: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
# All available actions: https://docs.fastlane.tools/actions

# fastlane reports which actions are used. No personal data is recorded.
# Learn more at https://github.com/fastlane/fastlane#metrics
